package nju.se.alibaba.algorithm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import nju.se.alibaba.dao.AlibabaDAO;
import nju.se.alibaba.model.Tmall;

public class PeriodAlgorithm extends Algorithm {
	public HashMap<Integer, HashSet<Integer>> getResults() {
		HashMap<Integer, HashSet<Integer>> result = new HashMap<Integer, HashSet<Integer>>();

		List<Tmall> tmalls = new ArrayList<Tmall>();
		for (int i = 1; i < 61; i++) {
			List<Tmall> tmall=AlibabaDAO.getPeriodAlgorithm(i);
			tmalls.addAll(tmall);
			System.out.println(i+":"+tmall.size());
		}
		
		System.out.println(tmalls.size());
		for (int i = 0; i < tmalls.size(); i++) {
			Tmall tmall = tmalls.get(i);
			Integer user_id = tmall.getUser_id();
			Integer brand_id = tmall.getBrand_id();
			if (result.containsKey(user_id)) {
				HashSet<Integer> brands = result.get(user_id);
				brands.add(brand_id);
				result.put(user_id, brands);
			} else {
				HashSet<Integer> brands = new HashSet<Integer>();
				brands.add(brand_id);
				result.put(user_id, brands);
			}
		}
		return result;
	}
}
